<div class="container-fluid">
    <div class="row-fluid" style="padding: 20px">
        <div class="col-sm-12 col-md-4  add-space">
            <div class="input-group input-group-md">
                <span class="input-group-addon">批次号</span>
                <select class="chosen-select form-control" tabindex="-1" name="batch_code" data-name-group="common">
                    <option value="" class="empty-opt">-- 请选择 --</option>
                    <volist name="batch_codes" id="item">
                        <option value="{$item}" >{$item}</option>
                    </volist>
                </select>
            </div>
        </div>
        <div class="col-md-2 add-space">
            <button class="btn btn-primary change_code">确认</button>
        </div>
    </div>
    <div class="clearfix"></div>
    <div class="container-fluid" style="padding: 20px">
        <table class="table table-bordered">
            <thead>
            <tr>
                <th hidden="hidden">ID</th>
                <th>批次号</th>
                <th>SKU</th>
                <th>帐号</th>
                <th>要求到货时间</th>
            </tr>
            </thead>
            <tbody id="code_info">
            <foreach name='needChangeCodeInfo' item='vo'>
                <tr>
                    <td hidden="hidden">{$vo.id}</td>
                    <td>{$vo.batch_code}</td>
                    <td>{$vo.sku}</td>
                    <td>{$vo.account_name}</td>
                    <td>{$vo.claim_arrive_time}</td>
                </tr>
            </foreach>
            </tbody>
        </table>
    </div>
    <div class="clearfix clear"></div>
</div>

<script type="text/javascript" src="__PUBLIC__/javascripts/admin/layer/layer.js"></script>
<script>
    $(document).ready(function () {
        $(".change_code").click(function () {
            if(!$("select[name='batch_code']").val()){
                //layer.msg("请选择要切换的批次号",{icon : 5});
                alert("请选择要切换的批次号");
                return false;
            }

            var confirm = window.confirm("您确定修改批次号？");
            if(confirm == false){
                return false;
            }

            var code_info = getCodeData();
            var target_code = $("select[name='batch_code']").val();
            var data =  {};
            data.code_info = code_info;
            data.target_code = target_code;
            doAjax(data);

        });

        /**
         * 描述：获取弹出框批次浩信息
         * @returns {Array}
         */
        function getCodeData() {
            var data = [];
            var code_info = {};
            $("#code_info").children("tr").each(function () {
                code_info.id = $(this).children("td").eq(0).text();
                code_info.batch_code = $(this).children("td").eq(1).text();
                code_info.sku = $(this).children("td").eq(2).text();
                code_info.account_name = $(this).children("td").eq(3).text();
                code_info.claim_arrive_time = $(this).children("td").eq(4).text();

                data.push(code_info);
            });

            return data;
        }

        function doAjax(data) {
            $.ajax({
                type : 'POST',
                url  : "__URL__/updateBatchCode",
                data : {data:data},
                dataType : "json",
                success : function ($result) {
                    if($result){
                        alert("批次号切换成功");
                    }else{
                        alert("切换失败");
                    }

                },
                error : function () {
                    alert("切换失败");
                }
            });

        }
    })
</script>